home *** CD-ROM | disk | FTP | other *** search
/ Champak 138 / Volume 138 Aug 19 2011 - Damaged.iso / Games / shadez.swf / scripts / Local / Game / CGame.as
Text File  |  2011-08-19  |  16KB  |  498 lines

  1. package Local.Game
  2. {
  3.    import Local.Audio.CAudio;
  4.    import Local.CGlobal;
  5.    import Local.CMain;
  6.    import Local.Draw.CWindow;
  7.    import Local.Draw.CWindow_Pause;
  8.    import Local.External.CKongregate;
  9.    import Local.Game.HUD.CHUD;
  10.    import Local.Game.Thing.CEffectExplosionLarge;
  11.    import Local.Game.Thing.CEffectExplosionMedium;
  12.    import Local.Game.Thing.CEffectExplosionSmall;
  13.    import Local.Game.Thing.CThingBase;
  14.    import Local.Game.World.CPosition;
  15.    import Local.Game.World.CWorld;
  16.    import Local.Math.CSecureNumber;
  17.    import STC9.IO.CKeyboard;
  18.    import STC9.System.CFrameSpeed;
  19.    import STC9.System.CProfiler;
  20.    import flash.display.Bitmap;
  21.    import flash.display.BitmapData;
  22.    import flash.display.DisplayObject;
  23.    import flash.display.Sprite;
  24.    import flash.events.Event;
  25.    
  26.    public class CGame extends Sprite
  27.    {
  28.       
  29.       public static const GAME_DIED:String = "GAME_DIED";
  30.       
  31.       public static const GAME_EXIT:String = "GAME_EXIT";
  32.       
  33.       public static const GAME_COMPLETE:String = "GAME_COMPLETE";
  34.       
  35.       public static var SECONDS:Number = 25;
  36.       
  37.       {
  38.          if(true)
  39.          {
  40.             GAME_COMPLETE = "GAME_COMPLETE";
  41.             if(true)
  42.             {
  43.                GAME_EXIT = "GAME_EXIT";
  44.                GAME_DIED = "GAME_DIED";
  45.             }
  46.             SECONDS = 25;
  47.          }
  48.       }
  49.       
  50.       private var mFadeOut:Bitmap;
  51.       
  52.       public var mWorld:CWorld;
  53.       
  54.       private var mInitialized:Boolean = false;
  55.       
  56.       private var mFrameSpeed:CFrameSpeed;
  57.       
  58.       public var mAudio:CAudio;
  59.       
  60.       private var mKeyboard:CKeyboard;
  61.       
  62.       public var mHUD:CHUD;
  63.       
  64.       public var mPause:Boolean;
  65.       
  66.       public var mTick:int;
  67.       
  68.       public var mDisposed:Boolean;
  69.       
  70.       private var mMain:CMain;
  71.       
  72.       private var mPauseWindow:CWindow;
  73.       
  74.       private var mGameCountOut:int;
  75.       
  76.       public function CGame()
  77.       {
  78.          if(true)
  79.          {
  80.             mInitialized = false;
  81.             if(true)
  82.             {
  83.                super();
  84.                addEventListener(Event.ADDED_TO_STAGE,Initialize);
  85.             }
  86.             CGlobal.SetField("CHEATS",false);
  87.          }
  88.       }
  89.       
  90.       private function ProcessFadeOut() : void
  91.       {
  92.          if(mFadeOut)
  93.          {
  94.             if((mFadeOut.alpha = mFadeOut.alpha - 0.05) < 0.05)
  95.             {
  96.                removeChild(mFadeOut);
  97.                mFadeOut.bitmapData.dispose();
  98.                mFadeOut = null;
  99.                mWorld.Start();
  100.             }
  101.          }
  102.       }
  103.       
  104.       public function get mScore() : CSecureNumber
  105.       {
  106.          return mHUD.mFundsSecure;
  107.       }
  108.       
  109.       public function Exit(param1:Event = null) : void
  110.       {
  111.          if(true)
  112.          {
  113.             dispatchEvent(new Event(GAME_EXIT));
  114.          }
  115.       }
  116.       
  117.       public function Process() : void
  118.       {
  119.          var _loc1_:int = 0;
  120.          ┬º┬ºpush(mInitialized);
  121.          if(true)
  122.          {
  123.             if(!┬º┬ºpop())
  124.             {
  125.                return;
  126.             }
  127.             mWorld.mScrollDelta.x = (!!CKeyboard.IsDown("LEFT") ? -1 : (!!CKeyboard.IsDown("RIGHT") ? 1 : 0)) * (!!CKeyboard.IsDown("SHIFT") ? 100 : 20);
  128.             mWorld.mLandscape.Scroll(mWorld.mScrollDelta.x,mWorld.mScrollDelta.y);
  129.             CProfiler.StartProfile("Game.Process");
  130.             ┬º┬ºpush(mHUD.mPlayState == "fast");
  131.          }
  132.          _loc1_ = !!┬º┬ºpop() ? 10 : 1;
  133.          loop0:
  134.          while(true)
  135.          {
  136.             ┬º┬ºpush(_loc1_);
  137.             while(true)
  138.             {
  139.                ┬º┬ºpush(Boolean(┬º┬ºpop()));
  140.                if(true)
  141.                {
  142.                   if(┬º┬ºpop())
  143.                   {
  144.                      if(true)
  145.                      {
  146.                         ┬º┬ºpop();
  147.                         ┬º┬ºpush(mDisposed);
  148.                      }
  149.                      ┬º┬ºpush(!┬º┬ºpop());
  150.                   }
  151.                }
  152.                if(!┬º┬ºpop())
  153.                {
  154.                   break;
  155.                }
  156.                mWorld.Process();
  157.                mHUD.Process();
  158.                CheckGameState();
  159.                ┬º┬ºpush(mTick);
  160.                if(true)
  161.                {
  162.                   continue loop0;
  163.                }
  164.             }
  165.             mAudio.Update(mWorld.mLandscape.mWorldArea);
  166.             CProfiler.AddDebug("Game.Tick",String(mTick));
  167.             CProfiler.StopProfile("Game.Process");
  168.             return;
  169.          }
  170.       }
  171.       
  172.       public function Resume(param1:Event = null) : void
  173.       {
  174.          mPause = false;
  175.          mKeyboard.Clear();
  176.          if(CGlobal.mSoundActive)
  177.          {
  178.             mAudio.Resume();
  179.          }
  180.          mHUD.Control_Play();
  181.       }
  182.       
  183.       public function Draw() : void
  184.       {
  185.          if(!mInitialized)
  186.          {
  187.             return;
  188.          }
  189.          CProfiler.StartProfile("Game.Draw");
  190.          mWorld.Draw();
  191.          mHUD.Draw();
  192.          CProfiler.StopProfile("Game.Draw");
  193.       }
  194.       
  195.       private function SetFadeOut(param1:DisplayObject) : void
  196.       {
  197.          if(true)
  198.          {
  199.             mFadeOut = new Bitmap(new BitmapData(CMain.mSize.width,CMain.mSize.height,false,0));
  200.             if(true)
  201.             {
  202.                mFadeOut.bitmapData.draw(param1);
  203.             }
  204.             mFadeOut.alpha = 1.1;
  205.          }
  206.       }
  207.       
  208.       public function Initialize(param1:Event = null) : void
  209.       {
  210.          if(true)
  211.          {
  212.             removeEventListener(Event.ADDED_TO_STAGE,Initialize);
  213.             if(true)
  214.             {
  215.                mMain = CMain(parent);
  216.                if(true)
  217.                {
  218.                   opaqueBackground = mMain.opaqueBackground;
  219.                   if(true)
  220.                   {
  221.                      SetFadeOut(mMain);
  222.                      if(true)
  223.                      {
  224.                         mInitialized = true;
  225.                         if(true)
  226.                         {
  227.                            mTick = 0;
  228.                            if(true)
  229.                            {
  230.                               mKeyboard = new CKeyboard(stage);
  231.                               if(true)
  232.                               {
  233.                                  mAudio = new CAudio();
  234.                                  if(true)
  235.                                  {
  236.                                     mHUD = new CHUD(this);
  237.                                     if(true)
  238.                                     {
  239.                                        addChild(mWorld = new CWorld(this));
  240.                                        if(true)
  241.                                        {
  242.                                           addChild(mHUD);
  243.                                           if(true)
  244.                                           {
  245.                                              mWorld.Initialise();
  246.                                           }
  247.                                           CGlobal.ResetLocalStats();
  248.                                        }
  249.                                        CGlobal.mStatsEnabled = false;
  250.                                     }
  251.                                     CProfiler.StartProfile("Game.Load");
  252.                                  }
  253.                                  new CEffectExplosionLarge(new CPosition()).Dispose();
  254.                               }
  255.                               new CEffectExplosionMedium(new CPosition()).Dispose();
  256.                            }
  257.                            new CEffectExplosionSmall(new CPosition()).Dispose();
  258.                         }
  259.                         CProfiler.StopProfile("Game.Load");
  260.                      }
  261.                      CGlobal.mStatsEnabled = true;
  262.                   }
  263.                   mFrameSpeed = new CFrameSpeed(25);
  264.                }
  265.                if(!mFadeOut)
  266.                {
  267.                }
  268.                ┬º┬ºgoto(addr140);
  269.             }
  270.             addChild(mFadeOut);
  271.          }
  272.          addr140:
  273.       }
  274.       
  275.       public function CheckGameState() : void
  276.       {
  277.          ┬º┬ºpush(mTick);
  278.          if(true)
  279.          {
  280.             ┬º┬ºpush(┬º┬ºpop() % SECONDS);
  281.             ┬º┬ºpush(0);
  282.             if(true)
  283.             {
  284.                if(┬º┬ºpop() == ┬º┬ºpop())
  285.                {
  286.                   if(mHUD.mFunds < 1000 && mWorld.mLevel.mFriendContainer.mNumChildren == 0 && !mHUD.mStrikesReady && !mHUD.mBuilding)
  287.                   {
  288.                      mHUD.mHealth = 0;
  289.                   }
  290.                }
  291.                ┬º┬ºpush(mHUD.mHealth);
  292.                ┬º┬ºpush(0);
  293.             }
  294.             if(┬º┬ºpop() <= ┬º┬ºpop())
  295.             {
  296.                Exit();
  297.             }
  298.             return;
  299.          }
  300.          ┬º┬ºgoto(addr36);
  301.       }
  302.       
  303.       public function Resize(param1:int, param2:int) : void
  304.       {
  305.          if(true)
  306.          {
  307.             mWorld.Resize(param1,param2);
  308.          }
  309.       }
  310.       
  311.       public function Pause() : void
  312.       {
  313.          mPause = true;
  314.          var _loc1_:*;
  315.          mPauseWindow = _loc1_ = new CWindow_Pause(stage);
  316.          addChild(_loc1_);
  317.          ┬º┬ºpush(mPauseWindow);
  318.          if(true)
  319.          {
  320.             ┬º┬ºpush(CWindow.DISPOSING);
  321.             if(true)
  322.             {
  323.                ┬º┬ºpop().addEventListener(┬º┬ºpop(),Resume);
  324.                addr40:
  325.                ┬º┬ºpush(mPauseWindow);
  326.                ┬º┬ºpush(CWindow_Pause.EXITGAME);
  327.             }
  328.             ┬º┬ºpop().addEventListener(┬º┬ºpop(),Exit);
  329.             mAudio.Pause();
  330.             return;
  331.          }
  332.          ┬º┬ºgoto(addr40);
  333.       }
  334.       
  335.       public function Update() : void
  336.       {
  337.          if(true)
  338.          {
  339.             if(mDisposed)
  340.             {
  341.                if(true)
  342.                {
  343.                   return;
  344.                }
  345.                addr151:
  346.                CProfiler.StopProfile("Game.Update");
  347.             }
  348.             else if(mPause)
  349.             {
  350.                if(true)
  351.                {
  352.                   mPauseWindow.Update();
  353.                   if(true)
  354.                   {
  355.                      ┬º┬ºgoto(addr154);
  356.                   }
  357.                   else
  358.                   {
  359.                      addr137:
  360.                      CProfiler.StartProfile("Game.Update");
  361.                   }
  362.                   ┬º┬ºgoto(addr154);
  363.                }
  364.                Process();
  365.                Draw();
  366.                ┬º┬ºgoto(addr151);
  367.             }
  368.             else
  369.             {
  370.                ┬º┬ºpush(!mFadeOut);
  371.                if(!mFadeOut)
  372.                {
  373.                   ┬º┬ºpop();
  374.                   if(true)
  375.                   {
  376.                      ┬º┬ºpush(Boolean(CKeyboard.IsReleased("P")));
  377.                      if(!Boolean(CKeyboard.IsReleased("P")))
  378.                      {
  379.                         ┬º┬ºpop();
  380.                         if(true)
  381.                         {
  382.                            addr50:
  383.                            if(mHUD.mPlayState == "pause")
  384.                            {
  385.                               if(true)
  386.                               {
  387.                                  Pause();
  388.                                  if(false)
  389.                                  {
  390.                                     addr125:
  391.                                     addr129:
  392.                                     if(CKeyboard.IsReleased("D"))
  393.                                     {
  394.                                     }
  395.                                     addr132:
  396.                                     if(mFrameSpeed.ProcessFrame())
  397.                                     {
  398.                                        addr135:
  399.                                        ProcessFadeOut();
  400.                                        ┬º┬ºgoto(addr137);
  401.                                     }
  402.                                  }
  403.                                  ┬º┬ºgoto(addr154);
  404.                               }
  405.                               CProfiler.ToggleMode();
  406.                               ┬º┬ºgoto(addr132);
  407.                            }
  408.                            else
  409.                            {
  410.                               if(CKeyboard.IsReleased("RETURN"))
  411.                               {
  412.                                  if(true)
  413.                                  {
  414.                                     if(CKeyboard.CompareString("FUND"))
  415.                                     {
  416.                                        if(true)
  417.                                        {
  418.                                           mKeyboard.Clear();
  419.                                           if(true)
  420.                                           {
  421.                                              ┬º┬ºpush(mHUD);
  422.                                              ┬º┬ºpush(mHUD.mFunds);
  423.                                              if(true)
  424.                                              {
  425.                                                 ┬º┬ºpush(┬º┬ºpop() + 1000000);
  426.                                              }
  427.                                              ┬º┬ºpop().mFunds = ┬º┬ºpop();
  428.                                              if(true)
  429.                                              {
  430.                                                 CGlobal.SetField("CHEATS",true);
  431.                                                 if(true)
  432.                                                 {
  433.                                                    CGlobal.SetField("HASCHEATED",true);
  434.                                                    addr101:
  435.                                                    if(!CKeyboard.CompareString("DEATH"))
  436.                                                    {
  437.                                                    }
  438.                                                    addr118:
  439.                                                    ┬º┬ºpush(Boolean(CKeyboard.IsDown("SHIFT")));
  440.                                                    if(Boolean(CKeyboard.IsDown("SHIFT")))
  441.                                                    {
  442.                                                       ┬º┬ºpop();
  443.                                                       ┬º┬ºgoto(addr125);
  444.                                                    }
  445.                                                    ┬º┬ºgoto(addr129);
  446.                                                 }
  447.                                                 mKeyboard.Clear();
  448.                                              }
  449.                                              mWorld.mLevel.KillAllEnemies();
  450.                                           }
  451.                                           CGlobal.SetField("CHEATS",true);
  452.                                        }
  453.                                        CGlobal.SetField("HASCHEATED",true);
  454.                                        ┬º┬ºgoto(addr118);
  455.                                     }
  456.                                     ┬º┬ºgoto(addr101);
  457.                                  }
  458.                               }
  459.                               ┬º┬ºgoto(addr101);
  460.                            }
  461.                         }
  462.                         ┬º┬ºgoto(addr125);
  463.                      }
  464.                      ┬º┬ºgoto(addr50);
  465.                   }
  466.                   ┬º┬ºgoto(addr135);
  467.                }
  468.                ┬º┬ºgoto(addr50);
  469.             }
  470.          }
  471.          addr154:
  472.       }
  473.       
  474.       public function Dispose() : void
  475.       {
  476.          if(true)
  477.          {
  478.             mWorld.Dispose();
  479.             if(true)
  480.             {
  481.                mAudio.Dispose();
  482.                if(true)
  483.                {
  484.                   mHUD.Dispose();
  485.                   if(true)
  486.                   {
  487.                      mKeyboard.Dispose();
  488.                   }
  489.                   mDisposed = true;
  490.                }
  491.                CGlobal.FlushStats();
  492.             }
  493.             CKongregate.UpdateStats();
  494.          }
  495.       }
  496.    }
  497. }
  498.